<?php

namespace App\Http\Controllers\admin;

use App\Http\Controllers\Controller;
use App\Models\Setting;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Hash;

class SettingController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index(Request $Request){
        $data = Setting::where('type',$Request->type)->where('status',1)->get();
        return response()->json(['code' => 200, 'message' => 'success','result'=>$data]);
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        $POSTONLY = Setting::POSTONLY;
        $input = $request->only($POSTONLY);
        $data = Setting::create($input);
        return response()->json(['code' => 200, 'message' => '操作成功']);
    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request)
    {
        $POSTONLY = Setting::POSTONLY;
        $input = $request->only($POSTONLY);
        $input['id'] = $request->id;
        $data = Setting::where('id',$input['id'])->update($input);
        return response()->json(['code' => 200, 'message' => '操作成功']);
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function delete($id)
    {
        if(!$id){
            return response()->json(['code' => 404, 'message' => '请选择要操作的记录']);
        }
        $data = Setting::find($id);
        $data->delete();
        return response()->json(['code' => 200, 'message' => '操作成功']);
    }

}
